215A - Bicycle Chain - CodeForces Solution


brute force implementation *900

Please click on ads to support us..

Python Code:

a=int(input())
b=map(int,input().split())
x=list(b)
c=int(input())
d=map(int,input().split())
y=list(d)
bos=[]
for i in range(len(y)):
    for k in range(len(x)):
        if y[i]%(x[k])==0:
            bos.append(y[i]/(x[k]))
print(bos.count(max(bos)))

C++ Code:

#include <bits/stdc++.h>
using namespace std;

#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pair<int,int>>
#define ll long long
#define ff first
#define ss second
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pq priority_queue
#define MAXN 100001



int main()
{
    int n,m;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    cin>>m;
    int b[m];
    for(int i=0;i<m;i++)
        cin>>b[i];
    int gearRatio=INT_MIN;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(b[j]%a[i]==0)
            {
                gearRatio=max(b[j]/a[i] , gearRatio);
            }
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(b[j]%a[i]==0)
            {
                if(b[j]/a[i]==gearRatio)
                   ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Comments

Submit
0 Comments
More Questions

677A - Vanya and Fence
1621A - Stable Arrangement of Rooks
472A - Design Tutorial Learn from Math
1368A - C+=
450A - Jzzhu and Children
546A - Soldier and Bananas
32B - Borze
1651B - Prove Him Wrong
381A - Sereja and Dima
41A - Translation
1559A - Mocha and Math
832A - Sasha and Sticks
292B - Network Topology
1339A - Filling Diamonds
910A - The Way to Home
617A - Elephant
48A - Rock-paper-scissors
294A - Shaass and Oskols
1213A - Chips Moving
490A - Team Olympiad
233A - Perfect Permutation
1360A - Minimal Square
467A - George and Accommodation
893C - Rumor
227B - Effective Approach
1534B - Histogram Ugliness
1611B - Team Composition Programmers and Mathematicians
110A - Nearly Lucky Number
1220B - Multiplication Table
1644A - Doors and Keys